<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<html>
<head>
    <title>Questionnaires List</title>
    <script src="<c:url value="/resources/scripts/jquery-1.7.7.min.js"/>" type="text/javascript"></script>
    <script src="<c:url value="/resources/scripts/script.js"/>" type="text/javascript"></script>
    <script src="<c:url value="/resources/scripts/jquery.tablesorter.min.js"/>" type="text/javascript"></script>
</head>
<body>

<c:set var="message" value="${param['errorMessage']}"/>
<c:if test="${message != null}">
    <span class="error"><fmt:message key="${message}"/></span>
</c:if>
<c:if test="${not empty questionnairesList}">
    <form:form id="setQuestionnaireInactive" method="POST">
        <input type="hidden" id="questionnaireId" name="questionnaireId"/>
    </form:form>

    <div class="qlist">
        <h4> Questionnaires list </h4>
    </div>
    <table id="questionnairesTable" class="tableSorter">
        <thead>
        <tr>
            <th>Title</th>
            <th>Category</th>
            <th>Creation date</th>
            <th>Active</th>
            <th>Action</th>
        </tr>
        </thead>
        <t:body>
            <c:forEach items="${questionnairesList}" var="questionnaire">
                <tr>
                    <td>${questionnaire.title}</td>
                    <td>${questionnaire.category.name}</td>
                    <td>${questionnaire.creationDate}</td>
                    <td>${questionnaire.active}</td>
                    <td>
                        <c:if test="${questionnaire.active==true}">
                            <a href="#" onclick="setInactive('${questionnaire.id}');">Set inactive</a>
                        </c:if>
                    </td>
                </tr>
            </c:forEach>
        </t:body>
    </table>
</c:if>

</br>
<div class="qlist">
    <a href="#" class="new_q" onclick="addQuestionnaire();">Add new questionnaire</a>
</div>
<br><br>

</body>
</html>